//
//  SWManagerCenterTableViewController.m
//  sc-cyan-ios
//
//  Created by lvjian01 on 2017/12/23.
//  Copyright © 2017年 greenbuilding. All rights reserved.
//

#import "SWManagerCenterTableViewController.h"
#import "SWManagerCenterTableViewCell.h"
#import "SWMyInquiryViewController.h"
#import "SWMySolicitingTableViewController.h"
#import "SWMyevaluationTableViewController.h"
#import "SWMyOperatersTableViewController.h"

@interface SWManagerCenterTableViewController ()

@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation SWManagerCenterTableViewController

- (NSArray *)dataArray{
    return @[
             @{@"section":@"租赁信息管理",@"rows":@[@"我的租赁信息",@"发布租赁信息",@"我的操作人员",@"添加操作人员"]},
             @{@"section":@"求租信息管理",@"rows":@[@"我的求租信息",@"发布求租信息"]},
             @{@"section":@"评价管理",@"rows":@[@"我的评价"]}
             ];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"sectionHeader"];
    
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSDictionary *sectionDic = [self.dataArray objectAtIndex:section];
    return [[sectionDic objectForKey:@"rows"] count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSArray *rows = [[self.dataArray objectAtIndex:indexPath.section] objectForKey:@"rows"];
    
    SWManagerCenterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SWManagerCenterTableViewCell class]) forIndexPath:indexPath];
    
    cell.titleLabel.text = [rows objectAtIndex:indexPath.row];
    
    // Configure the cell...
    
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    UITableViewHeaderFooterView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"sectionHeader"];
    
    header.contentView.backgroundColor = UIColorFromRGB(0xF5F5F5);

    header.textLabel.font = SYSTEMFONT(12);
    header.textLabel.textColor = [UIColor redColor];
    header.textLabel.text = [[self.dataArray objectAtIndex:section] objectForKey:@"section"];
    return header;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0001;
}

#pragma mark -- tableview delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *titleStr = [[[self.dataArray objectAtIndex:indexPath.section] objectForKey:@"rows"] objectAtIndex:indexPath.row];
    
    if ([titleStr isEqualToString:@"我的操作人员"]) {
        SWMyOperatersTableViewController *operaterVC = [SWMyOperatersTableViewController dd_instanceFromStoryboard];
        operaterVC.title = @"我的操作人员";
        [self.navigationController showViewController:operaterVC sender:nil];
    }
    
    
    if ([titleStr isEqualToString:@"我的租赁信息"]) {
        SWMyInquiryViewController *myvc = [SWMyInquiryViewController dd_instanceFromStoryboard];
        myvc.title = titleStr;
        [self.navigationController showViewController:myvc sender:nil];
    }else if ([titleStr isEqualToString:@"我的求租信息"]){
        SWMySolicitingTableViewController *solicitVC = [SWMySolicitingTableViewController dd_instanceFromStoryboard];
        solicitVC.title = titleStr;
        [self.navigationController showViewController:solicitVC sender:nil];
    }
    
    else if ([titleStr isEqualToString:@"我的评价"]){
        SWMyevaluationTableViewController *evaluationVC = [SWMyevaluationTableViewController dd_instanceFromStoryboard];
        evaluationVC.title = titleStr;
        [self.navigationController showViewController:evaluationVC sender:nil];
    }
}


@end
